package com.wish233.wiliwiliapi.fallback;

import com.wish233.wiliwiliapi.client.UserClient;
import com.wish233.wiliwiliapi.domain.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author WHH
 * 用户服务降级处理
 */
@Slf4j
public class UserClientFallback implements FallbackFactory<UserClient> {
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            @Override
            public Map<Long, UserDTO> getUserByIdBatch(Set<Long> userIds) {
                return Collections.emptyMap();
            }

            @Override
            public List<UserDTO> getUserByIdBatchSorted(Set<Long> userIds) {
                return Collections.emptyList();
            }

            @Override
            public UserDTO getUserDTOById(Long id) {
                UserDTO userDTO = new UserDTO();
                userDTO.setNickname("匿名用户");
                return userDTO;
            }
        };
    }
}